package com.example.wusp.controller;

import com.example.wusp.model.Restaurant;
import com.example.wusp.service.RestaurantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController  // 标记为RESTful控制器
public class RestaurantController {

    @Autowired
    private RestaurantService restaurantService;  // 自动注入服务层

    @GetMapping("/restaurants")  // 处理GET请求
    public String getRestaurants() {
        return "惊喜一餐";
    }

    @GetMapping("/restaurants/search")  // 使用 @RequestParam 获取查询参数
    public String searchRestaurant(@RequestParam String name) {
        return "正在查找餐厅: " + name;
    }

    @PostMapping("/restaurants/add")  // 使用 @RequestBody 处理POST请求体
    public String addRestaurant(@RequestBody Restaurant restaurant) {
        return "添加餐厅: " + restaurant.getName();
    }

    @GetMapping("/restaurant/details")  // 使用自动注入的服务类
    public String getRestaurantDetails() {
        return restaurantService.getRestaurantDetails();
    }
}
